package com.ieducc.ffmpegdemo.controller;

import com.ieducc.ffmpegdemo.ffmpegutil.EncoderException;
import com.ieducc.ffmpegdemo.ffmpegutil.FfmpegService;
import com.ieducc.ffmpegdemo.ffmpegutil.MultimediaInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @Autowired
    private FfmpegService ffmpegService;

    @GetMapping("/getVideoDetail")
    public void getVideoDetail() {
        String filePath = "https://test.ieducc.com/yr2awpn6xep1637543708781.mp4";

        try {
            MultimediaInfo multimediaInfo = ffmpegService.getInfoByUrl(filePath);
            final int bitRate = multimediaInfo.getVideo().getBitRate();
            System.out.println(bitRate);
        } catch (EncoderException e) {
            e.printStackTrace();
        }
    }


    @GetMapping("/compressVideo")
    public String compressVideo() {
        String inputPath = "G:\\yssp\\A25.mp4";
        String outputPath = "G:\\yssp\\A25_out.mp4";

        try {
            ffmpegService.compressVideo(inputPath, outputPath);
        } catch (EncoderException e) {
            e.printStackTrace();
        }
        return "success";

    }
}
